package br.com.ordersys.framework.db;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class SessionAttributes {
	private Map<String, Object> atts = new HashMap<String, Object>();

	public void put(String name, Object v) {
		atts.put(name, v);
	}

	public Object get(String name) {
		return get(name, null);
	}

	public Object get(String name, Object def) {
		name = name.toLowerCase();
		return atts.containsKey(name) ? atts.get(name) : def;
	}

	public int asInt(String name, int def) {
		Number v = (Number) get(name, def);
		return v.intValue();
	}

	public int asInt(String name) {
		return asInt(name, 0);
	}

	public double asDouble(String name, double def) {
		Number v = (Number) get(name, def);
		return v.doubleValue();
	}

	public double asDouble(String name) {
		return asDouble(name, 0);
	}

	public BigDecimal asBigDecimal(String name, BigDecimal def) {
		return (BigDecimal) get(name, def);
	}

	public BigDecimal asBigDecimal(String name) {
		return (BigDecimal) get(name, null);
	}

	public String asString(String name, String def) {
		return (String) get(name, def);
	}

	public String asString(String name) {
		return (String) get(name, null);
	}
	
	public boolean contains(String name){
		return atts.containsKey(name);
	}

}
